Skip to content

Add ElicitAsync<T> (#630) #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mehrandvd
Copy link

  • Added a generic class ElicitResult<T> for typed content.
  • Added ElicitAsync<T> method in McpServerExtensions.cs to request user input and construct schemas based on type T.
  • Implemented schema building logic to handle primitive types and enums, ignoring unsupported types.
  • Introduced ElicitationTypedTests.cs for testing the new elicitation functionality with typed forms.
  • Verified naming policies in tests to ensure correct serialization casing.
  • Defined SampleForm and CamelForm classes for expected input shapes, including unsupported properties for schema testing.
  • Created JSON serialization contexts for both forms using source generation for improved performance.

Motivation and Context

It resolves #630

How Has This Been Tested?

I've added proper unit tests for it.

Breaking Changes

No breaking changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

No additional notes.

mehrandvd and others added 2 commits August 19, 2025 02:39
- Refactored `ElicitResult` to a generic class `ElicitResult<T>` for typed content.
- Added `ElicitAsync<T>` method in `McpServerExtensions.cs` to request user input and construct schemas based on type `T`.
- Implemented schema building logic to handle primitive types and enums, ignoring unsupported types.
- Introduced `ElicitationTypedTests.cs` for testing the new elicitation functionality with typed forms.
- Verified naming policies in tests to ensure correct serialization casing.
- Defined `SampleForm` and `CamelForm` classes for expected input shapes, including unsupported properties for schema testing.
- Created JSON serialization contexts for both forms using source generation for improved performance.
@mehrandvd
Copy link
Author

@stephentoub Could you review this, please?

return new ElicitResult<T?> { Action = raw.Action, Content = typed };
}

private static ElicitRequestParams.RequestSchema BuildRequestSchemaFor<T>(JsonSerializerOptions serializerOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we'll want to leverage AIFunction.ReturnJsonSchema, but @eiriktsarpalis would be the best person to ask about this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there's no AIFunction here, we'd probably want to call AIJsonUtilities.CreateJsonSchema directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an ElicitAsync<T> overload
3 participants